package com.zhangzhan.gulimallsearch.web;

import com.alibaba.fastjson.JSON;
import com.zhangzhan.gulimallsearch.service.SearchService;
import com.zhangzhan.gulimallsearch.vos.SearchParam;
import com.zhangzhan.gulimallsearch.vos.SearchResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/6/23 2:33
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;


    @RequestMapping(value = "/list.html", method = RequestMethod.GET)
    public String listPage(Model model, SearchParam searchParam, HttpServletRequest httpServletRequest) {

        searchParam.set_uri(httpServletRequest.getQueryString());
        SearchResult result = searchService.listPage(searchParam);
        System.out.println(JSON.toJSONString(result));
        model.addAttribute("result",result);
        return "list";
    }

}
